package stone;

import stone.ast.ASTree;
import stone.ast.NullStmnt;
import stone.util.LexerUtil;

public class BasicInterpreter {
  public static void main(String[] args) throws ParseException {
    if (args.length != 1) {
      System.out.println("请给出程序");
      return;
    }
    run(args[0], new BasicParser(), new BasicEnv());
  }

  public static void run(String 程序, BasicParser bp, Environment env) throws ParseException {
    Lexer lexer = LexerUtil.新建词法分析器(程序);
    Token token = lexer.peek(0);
    while (token != Token.EOF) {
      ASTree t = bp.parse(lexer);
      if (!(t instanceof NullStmnt)) {
        Object r = ((BasicEvaluator.ASTreeEx) t).eval(env);
        System.out.println("=> " + r);
      }
      token = lexer.peek(0);
    }
  }
}
